package com.dlnu.shoping.shopping.controller;

import com.dlnu.shoping.shopping.common.Result;
import com.dlnu.shoping.shopping.service.IAdService;
import com.dlnu.shoping.shopping.service.ShoppingCartService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/cart")
public class ShoppingCartController {
    @Resource
    private ShoppingCartService shoppingCartService;

//    通过用户id对购物车进行查询
    @RequestMapping("/search")
    public Result search(@RequestParam Integer useId) {
        return shoppingCartService.searchByUseId(useId);
    }

//    删除
    @RequestMapping("/delete")
    public Result delete(@RequestParam Integer useId,@RequestParam Integer proId) {
        return shoppingCartService.delete(useId,proId);
    }

//    添加
    @RequestMapping("/addCart")
    public Result addCart(@RequestParam Integer useId,@RequestParam Integer proId,@RequestParam Integer proNum,@RequestParam(required = false) String size ) {
        return shoppingCartService.addCart(useId,proId,proNum,size);
    }

//    修改商品数量
    @RequestMapping("/alter")
    public Result alterProNum(@RequestParam Integer useId,@RequestParam Integer proId,@RequestParam Integer proNum) {
        return shoppingCartService.alterProNum(useId, proId, proNum);
    }
}
